// 引入 react 依赖
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Platform, DeviceEventEmitter, AsyncStorage, Alert, InteractionManager } from 'react-native';
import Storage from 'react-native-storage';
import { ToastExample, BodyPlusModule } from './nativeModules';

// 引入第三方依赖
import * as WeChat from 'react-native-wechat';
import { Actions } from 'react-native-router-flux';
import { Toast, Portal } from '@ant-design/react-native';
import RNFetchBlob from 'react-native-fetch-blob'
import axios from 'axios';
import moment from 'moment';
import request from '../api/request';
const { fs } = RNFetchBlob

// antd 按需加载

// 引入 处理数据 所需文件
import { deliveryAddressDefault, my, myCoin, myCv, myIntegral, cardLike, plateFollow, cardFollowAccount } from '../module/module.js';

// redux
import store from '../store/store';
import * as ActionTypes from '../constants/constants.js';

// request
const Dimensions = require('Dimensions');

// 接口前缀
export const pathHead = 'http://39.106.180.25';
export const path = `${pathHead}:8091`;

// 微信支付使用 wx0635a1d496b696a0
export const AppId = 'wx0635a1d496b696a0';
export const secret = '2753caee9d34b329c723bc9b5a11ce47';
// export const AppId = 'wx524a95e535397f6e'
// export const secret = 'cb2680622f2a5674f57b414a7aed61db'

// 财付通商家id
export const payId = '1576317721';

// 商家id
export const shopnum = 'S160616155813';

export const longitude = 132.639308;
export const latitude = 47.257497;


export const ScreenWidth = Dimensions.get('window').width;
export const ScreenHeight = Dimensions.get('window').height;
export const ScreenScale = Dimensions.get('window').scale;

export const press = (fn) => {
  requestAnimationFrame(() => {
    fn();
  });
};

export const size = (number, type) => {
  if (type == 'interval') {
    return ScreenWidth - number - number;
  }
  return (number / 750) * ScreenWidth;
};

// 初始化 storage
export const storage = new Storage({
  // 最大容量，默认值1000条数据循环存储
  size: 9999999999999,

  // 存储引擎：对于RN使用AsyncStorage，对于web使用window.localStorage
  // 如果不指定则数据只会保存在内存中，重启后即丢失
  storageBackend: AsyncStorage,

  // 数据过期时间，默认一整天（1000 * 3600 * 24 毫秒），设为null则永不过期
  defaultExpires: null,

  // 读写时在内存中缓存数据。默认启用。
  enableCache: true,

  // 如果storage中没有相应数据，或数据已过期，
  // 则会调用相应的sync方法，无缝返回最新数据。
  // sync方法的具体说明会在后文提到
  // 你可以在构造函数这里就写好sync的方法
  // 或是在任何时候，直接对storage.sync进行赋值修改
  // 或是写到另一个文件里，这里require引入
  // sync: {
  //     // sync方法的名字必须和所存数据的key完全相同
  //     // 方法接受的参数为一整个object，所有参数从object中解构取出
  //     // 这里可以使用promise。或是使用普通回调函数，但需要调用resolve或reject。
  //     user(params) {
  //         let { user_no, resolve, reject, syncParams: { extraFetchOptions, someFlag } } = params;
  //         getUserInfo(user_no, (res) => {
  //             // 成功则调用resolve
  //             resolve && resolve(res);
  //         }, () => {
  //             // 失败则调用reject
  //             reject && reject(new Error('data parse error'));
  //         })
  //     }
  // }

});

// 清除图片缓存
export function clearCache() {
}

// 往 storage 中保存指定信息
export function saveData(key, data) {
  // console.log('saveData ———— ', key, data)
  storage.save({
    key, // 注意:请不要在key中使用_下划线符号!
    data,
    // 如果不指定过期时间，则会使用defaultExpires参数
    // 如果设为null，则永不过期
    expires: null,
  }).then(res => {
    // console.log(res)
  });
}

// 从 storage 中获取指定信息
export function loadData(key, callback) {
  return new Promise((resolve, reject) => {
    // 请求账户信息
    storage.load({
      key,
      // autoSync(默认为true)意味着在没有找到数据或数据过期时自动调用相应的sync方法
      autoSync: true,
      // syncInBackground(默认为true)意味着如果数据过期，
      // 在调用sync方法的同时先返回已经过期的数据。
      // 设置为false的话，则等待sync方法提供的最新数据(当然会需要更多时间)。
      syncInBackground: true,
    }).then((res) => {
      console.log('loadData ———— end', key, res)
      resolve(res)
    }).catch((err) => {
      console.log('loadData ———— error', key, err)
      reject(null)
    });
  }).catch(error => {
    console.log(error)
  })
}

// 从 storage 中删除指定信息
export function removeData(key, callback) {
  // 请求账户信息
  storage.remove({
    key,
  });
}


// 获取登录后用户信息
export async function getUserInfo(user_no, success, error) {
  const { dispatch } = this.props;
  const res = await request.getUserInfo(user_no);
  saveData('user', res.data);
  dispatch({
    type: ActionTypes.GET_USER_INFO,
    data: res.data,
  });
}

// 获取用户信息
export async function isUser(success, error) {
  return new Promise((resolve, reject) => {
    loadData('user', (res) => {
      resolve(res);
      if (Object.prototype.toString.call(res) == '[object Object]') {
        success ? success() : null;
      } else {
        reject();
        error ? error() : null;
      }
    }, error => reject(error));
  });
}


export const getStatusHeight = () => {
  let height = 0;
  if (Platform.OS == 'ios') {
    height = 22;
  }
  if (Platform.OS == 'ios' && ScreenWidth / ScreenHeight < 9 / 16) {
    height = 44;
  }
  return height;
};

export const getHeaderHeight = () => {
  const height = getStatusHeight() + 44;
  return height;
};


export const requestMessage = (res, loading, message) => {
  Toast.remove(loading);
  return new Promise((resolve, reject) => {
    if (res.error) {
      if (message) {
        Toast.info(message.error, 1, null, false);
      }
      reject(res);
    } else if (res.data) {
      if (res.data.code == 200 || res.data.code == 1000) {
        if (message) {
          Toast.success(message.success, 1, null, false);
        }
        resolve(res.data);
      } else {
        if (message) {
          Toast.info(message.error, 1, null, false);
        }
        reject(res.data);
      }
    } else {
      if (message) {
        Toast.info(message.error, 1, null, false);
      }
      reject(res.data);
    }
  });
};


export const requstPromise = (res, callback) => {
  return new Promise((resolve, reject) => {
    if (res && res.code && res.code == 200) {
      callback ? callback() : null
      resolve(res);
    } else {
      reject(res);
    }
  })
}

export const bodyPlus = {

  // 搜索附近的设备
  search: () => {
    BodyPlusModule.search()
  },
  // 连接指定的设备
  connectDevice: (macAddress, deviceSn, rssi, deviceName, isDfuStatus) => {
    BodyPlusModule.connectDevice(macAddress, deviceSn, rssi, deviceName, isDfuStatus)
  },
  // 通过已有sn连接设备
  connectDeviceBySn: (sn) => {
    BodyPlusModule.connectDeviceBySn(sn)
  },
  // 解绑并断开现有连接
  disConnect: () => {
    BodyPlusModule.disConnect()
  },
  // 开始心率采集
  startEcg: () => {
    BodyPlusModule.startEcg()
  },
  // 关闭心率采集
  closedEcg: () => {
    BodyPlusModule.closedEcg()
  },
  // 修改设备名称
  reName: (name) => {
    BodyPlusModule.reName(name)
  },
  // 开启离线
  startOffline: () => {
    store.dispatch({
      type: ActionTypes.setOfflineStatus,
      data: true
    })
    BodyPlusModule.startOffline()
  },
  // 关闭离线
  finishOffline: () => {
    store.dispatch({
      type: ActionTypes.clearOfflineStatus,
    })
    BodyPlusModule.finishOffline()
  },

  // 修改名称成功
  reNameSucceed: (callback) => {
    DeviceEventEmitter.addListener('reNameSucceed', (e) => {
      console.log(e, '修改名称成功')
      if (callback) {
        callback(e)
      }
    });
  },

  // 蓝牙打开
  bleStateOn: (callback) => {
    DeviceEventEmitter.addListener('bleStateOn', (e) => {
      console.log(e, '蓝牙打开')
      if (callback) {
        callback(e)
      }
    });
  },

  // 离线状态
  offlineStatus: (callback) => {
    DeviceEventEmitter.addListener('offlineStatus', (e) => {
      // console.log(e, '离线状态')
      store.dispatch({
        type: ActionTypes.clearOfflineStatus,
      })
      if (callback) {
        callback(e)
      }
    });
  },
  // 信号更改反馈
  rssi: (callback) => {
    DeviceEventEmitter.addListener('rssi', (e) => {
      // console.log(e, '信号更改反馈')
      if (callback) {
        callback(e)
      }
    });
  },
  // 回调Body数据 肌电 心率 呼吸
  dataCallBack: (callback) => {
    DeviceEventEmitter.addListener('dataCallBack', (e) => {
      // console.log(e, '回调Body数据 肌电 心率 呼吸')
      // ecgData
      if (callback) {
        callback(e)
      }
    });
  },

  // 电量读取的返回、电量改变的回调
  powerLevel: (callback) => {
    DeviceEventEmitter.addListener('powerLevel', (e) => {
      // console.log(e, '电量读取的返回、电量改变的回调')
      if (callback) {
        callback(e)
      }
    });
  },
  // 重连成功的回调
  connectDeviceSuccess: (callback) => {
    DeviceEventEmitter.addListener('connectDevice', (e) => {
      console.log(e, '重连成功的回调')
      store.dispatch({
        type: ActionTypes.setConnectStatus,
        data: true
      })
      if (callback) {
        callback(e)
      }
    });
  },
  // 连接断开的回调
  deviceDisconnect: (callback) => {
    DeviceEventEmitter.addListener('deviceDisconnect', (e) => {
      console.log(e, '连接断开的回调')
      store.dispatch({
        type: ActionTypes.clearPowerLevel
      })
      store.dispatch({
        type: ActionTypes.clearConnectStatus,
      })
      if (callback) {
        callback(e)
      }
    });
  },
  // Core位置变化的回调（主动触发）
  coreModule: (callback) => {
    DeviceEventEmitter.addListener('coreModule', (e) => {
      console.log(e, 'Core位置变化的回调（主动触发）')
      if (callback) {
        callback(e)
      }
    });
  },
  // 搜索的设备列表的回调
  deviceList: (callback) => {
    DeviceEventEmitter.addListener('deviceList', (e) => {
      console.log(e, '搜索的设备列表的回调')
      if (callback) {
        callback(e)
      }
    });
  },
  // 心率监测脱落的回调
  heartDataError: (callback) => {
    DeviceEventEmitter.addListener('heartDataError', (e) => {
      console.log(e, '心率监测脱落的回调')
      if (callback) {
        callback(e)
      }
    });
  }
}

export const initApp = async () => {
  const { dispatch } = store
  let token = await loadData('token')
  let loginInfo = await loadData('loginInfo')
  let userInfo = await loadData('userInfo')
  if (loginInfo) {
    dispatch({
      type: ActionTypes.setLoginInfo,
      data: loginInfo,
    })
  }
  if (userInfo) {
    dispatch({
      type: ActionTypes.setUserInfo,
      data: userInfo,
    })
  }
  if (token) {
    dispatch({
      type: ActionTypes.setToken,
      data: token,
    })
    await initUser()
    await deliveryAddressDefault()
    Actions.index({ type: "reset" })
  } else {
    Actions.login({ type: "reset" })
  }
}

export const loadingApp = async (loading, callback) => {
  await initUser()
  await deliveryAddressDefault()
  Portal.remove(loading)
  // console.log('loadingApp')
  Actions.mall({ type: "reset" })
  // callback ? callback() : Actions.mall()

}

export const initUser = () => {
  const { dispatch } = store
  return new Promise(async (resolve, reject) => {
    let user = await my()
    let coin = await myCoin()
    let cv = await myCv()
    let integral = await myIntegral()
    if (user && coin && cv && integral) {
      resolve()
    } else {
      reject()
    }
  })
}

export const borderColor = '#DDD'
export const defaultTextColor = '#666'
export const hotTextColor = '#E5C67B'
export const inputPlaceholderColor = "#999999"
export const inputTextColor = "#333"
export const inputHighlightPlaceholderColor = "#999999"
export const inputHighlightTextColor = "#fff"

export const borderBottom = (option) => {
  return {
    borderBottomWidth: option && option.width ? option.width : .5,
    borderColor: option && option.color ? option.color : borderColor,
  }
}

export const borderTop = (option) => {
  return {
    borderTopWidth: option && option.width ? option.width : .5,
    borderColor: option && option.color ? option.color : borderColor,
  }
}

export const borderLeft = (option) => {
  return {
    borderLeftWidth: option && option.width ? option.width : .5,
    borderColor: option && option.color ? option.color : borderColor,
  }
}

export const borderRight = (option) => {
  return {
    borderRightWidth: option && option.width ? option.width : .5,
    borderColor: option && option.color ? option.color : borderColor,
  }
}



export const validation = {
  phone(value) {
    var reg = /^\d{9,11}$/
    return reg.test(value)
  },
  email(value) {
    var reg = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/
    return reg.test(value)
  },
}


export const PrefixInteger = (num, n) => {
  return (Array(n).join(0) + num).slice(-n);
}

export const countDown = (payEndTime) => {
  let m1 = moment()
  let m2 = moment(payEndTime)
  var du = moment.duration(m2 - m1, 'ms'),
    hours = du.get('hours'),
    mins = du.get('minutes'),
    ss = du.get('seconds');
  if (hours <= 0 && mins <= 0 && ss <= 0) {
    return null
  } else {
    return PrefixInteger(hours, 2) + ':' + PrefixInteger(mins, 2) + ':' + PrefixInteger(ss, 2)
  }
}



// 是否安装微信
export function isWXAppInstalled() {
  return new Promise((resolve, reject) => {
    WeChat.isWXAppInstalled().then((isInstalled) => {
      if (isInstalled) {
        resolve()
      } else {
        reject()
        if (Platform.OS == 'ios') {
          Alert.alert('没有安装微信', '是否安装微信？', [
            { text: '取消' },
            { text: '确定', onPress: () => { this.installWechat(); } },
          ])
        } else {
          Alert.alert('没有安装微信', '请先安装微信客户端在进行登录', [{ text: '确定' }]);
        }
      }
    }).catch((error) => {
      console.log(error)
      reject()
    });
  }).catch((error) => {
    console.log(error)
  });
}


// 微信支付
export function WeChatPay(options) {
  return new Promise((resolve, reject) => {
    isWXAppInstalled().then(res => {
      console.log({
        partnerid: options.partnerid,
        prepayid: options.prepayid,
        package: options.package,
        noncestr: options.noncestr,
        timestamp: options.timestamp,
        sign: options.sign,
      })
      WeChat.pay({
        partnerid: options.partnerid,
        prepayid: options.prepayid,
        package: options.package,
        noncestr: options.noncestr,
        timestamp: options.timestamp,
        sign: options.sign,
      }).then((success) => {
        console.log(success, 567)
        // 微信支付成功
        resolve(success);
      }).catch((error) => {
        console.log(error, 571)
        // 微信支付失败
        reject(error);
      });
    }).catch(error => {
      console.log(error, 576)
      // 调用微信支付失败
      reject(error);
    })
  });
}


// 微信登录
export function WeChatLogin() {
  return new Promise((resolve, reject) => {
    const scope = 'snsapi_userinfo';
    const state = 'wechat_sdk_demo';
    // 判断微信是否安装
    isWXAppInstalled().then(() => {
      // 发送授权请求
      WeChat.sendAuthRequest(scope, state).then((responseCode) => {
        console.log(responseCode)
        // 返回code码，通过code获取access_token
        axios.get('https://api.weixin.qq.com/sns/oauth2/access_token', {
          params: {
            appid: AppId,
            secret,
            code: responseCode.code,
            grant_type: 'authorization_code',
          },
        }).then((accessTokenRes) => {
          // 通过wx  access_token  openid 获取微信用户信息
          axios.get('https://api.weixin.qq.com/sns/userinfo', {
            params: {
              access_token: accessTokenRes.data.access_token,
              openid: accessTokenRes.data.openid,
            },
          }).then((res) => {
            console.log(res)
            resolve(res)
          }).catch((error) => {
            Toast.hide();
            Alert.alert('获取微信用户信息失败', error.toString(), [{ text: '确定' }]);
            reject()
          });
        }).catch((error) => {
          Toast.hide();
          Alert.alert('获取access_token失败', error.toString(), [{ text: '确定' }]);
          reject()
        });
      }).catch((error) => {
        Alert.alert('登录授权发生错误', error.toString(), [{ text: '确定' }]);
        reject()
      });
    }).catch((error) => {
      Alert.alert('操作失败', error.toString(), [{ text: '确定' }]);
      reject()
    });
  });
}

// 分享到朋友圈
export function WeChatShareToTimeline(options) {
  return new Promise((resolve, reject) => {
    // 判断微信是否安装
    isWXAppInstalled().then(() => {
      // 发送授权请求
      let shareOptions = {
        title: option.title,
        description: option.description,
        // String	消息的Thumb图像，可以是uri或资源id
        thumbImage: options.thumbImage,
        // String	{news/text/imageUrl/imageFile/imageResource/video/audio/file}
        type: options.type,
      }

      // String	如果type为news,则使用此分享url
      if (options.type == 'news') {
        shareOptions.webpageUrl = options.url
      }

      // String	如果type为image,则使用此分享url
      if (options.type == 'image') {
        shareOptions.imageUrl = options.url
      }

      // String	如果type为video,则使用此分享url
      if (options.type == 'video') {
        shareOptions.videoUrl = options.url
      }

      // String	如果type为audio,则使用此分享url
      if (options.type == 'audio') {
        shareOptions.musicUrl = options.url
      }

      // String	如果type为file,则使用此获取本地文件
      if (options.type == 'file') {
        shareOptions.filePath = options.url
      }

      // String	如果type为file,则使用此提供文件类型
      if (options.type == 'file') {
        shareOptions.fileExtension = options.fileType
      }

      WeChat.shareToTimeline(shareOptions).then((res) => {
        console.log(res)
      }).catch((error) => {
        console.log(error)
        Alert.alert('分享到朋友圈发生错误', error.toString(), [{ text: '确定' }]);
      });
    }).catch((error) => {
      console.log(error)
      Alert.alert('分享失败', error.toString(), [{ text: '确定' }]);
    });
  });
}

// 分享到朋友圈
export function WeChatShareToSession(options) {
  console.log('开始分享')
  return new Promise((resolve, reject) => {
    // 判断微信是否安装
    console.log('判断微信是否安装')
    isWXAppInstalled().then(() => {
      // https://github.com/yorkie/react-native-wechat
      console.log('调用分享')
      console.log(options)
      try {
        WeChat.shareToSession(options).then((res) => {
          console.log(res)
          resolve(res)
        }).catch((error) => {
          console.log(error)
          reject()
          Alert.alert('分享到微信发生错误', error.toString(), [{ text: '确定' }]);
        });
      } catch (error) {
        console.log(error)
      }
    }).catch((error) => {
      console.log(error)
      reject()
      Alert.alert('分享失败', error.toString(), [{ text: '确定' }]);
    });
  }).catch((error) => {
    console.log(error)
    Alert.alert('分享失败', error.toString(), [{ text: '确定' }]);
  }).catch(error => {
    console.log(error)
  });
}

//监听分享状态
export function WeChatAddListener(str) {
  return new Promise((resolve, reject) => {
    let resp = {
      // 登录监听字段
      auth: 'SendAuth.Resp',
      // 支付监听字段
      pay: 'PayReq.Resp',
      // 分享监听字段
      shard: 'SendAuth.Resp'
    }
    wechat.addListener(resp[str], (response) => {
      if (parseInt(response.errCode) === 0) {
        resolve('分享成功');
      } else {
        reject('分享失败');
      }
    });
  })
}

//监听一次分享状态
export function WeChatOnce(str) {
  return new Promise((resolve, reject) => {
    let resp = {
      // 登录监听字段
      auth: 'SendAuth.Resp',
      // 支付监听字段
      pay: 'PayReq.Resp',
      // 分享监听字段
      shard: 'SendAuth.Resp'
    }
    wechat.once(resp[str], (response) => {
      if (parseInt(response.errCode) === 0) {
        resolve('分享成功');
      } else {
        reject('分享失败');
      }
    });
  })
}


export function FileUpload(image) {
  return new Promise((resolve, reject) => {
    let PATH = Platform.OS == 'ios' ? image.path.replace('file:///', '') : image.path;
    RNFetchBlob.fetch('POST', path + '/upload',
      {
        // 上传图片要设置Header
        'Content-Type': 'multipart/form-data',
        'token': store.getState().token
      },
      [{
        name: 'file',
        filename: 'file',
        data: RNFetchBlob.wrap(PATH)
      }])
      .uploadProgress((written, total) => {
        // 本地查找进度
        console.log(written, total)
      })
      .progress((received, total) => {
        let perent = received / total;
        // 上传进度打印
        console.log(perent);
      })
      .then((response) => {
        console.log(response)
        return response.json()
      })
      .then((response) => {
        // 上传信息返回
        console.log(response);
        resolve(response)
      })
      .catch((error) => {
        // 错误信息
        console.log(error);
        reject(error)
      });
  })
}


export function ImageFileSave(path) {
  return new Promise((resolve, reject) => {
    // 图片存储的基本目录
    const getImagesCacheDirectory = () => `${fs.dirs.CacheDir}/cache-images`
    // 图片存储临时目录
    const getTmpDir = () => `${getImagesCacheDirectory()}/tmp`
    const taskId = `billpic${parseInt(Math.random(100) * 100)}${new Date().getMilliseconds()}.png`
    const tmpPath = `${getTmpDir()}/${taskId}`
    console.log(tmpPath)
    RNFetchBlob.config({
      path: tmpPath
    }).fetch('GET', path).then(res => {
      resolve(res)
    }).catch(e => {
      Toast.info('保存失败')
      reject()
      console.log(e)
    })
  })
}




export const defaultDataList = {
  total: 0,
  size: 10,
  current: 1,
  pages: 1,
  records: []
}

export function defaultPage() {
  const { dataList: { current, size } } = this.state
  return {
    current,
    size,
  }
}


export function onEndReached() {
  const { dataList: { current, size, records, total } } = this.state
  if (records.length < total) {
    this.setState({ dataList: { size, records, total, current: current + 1 } }, () => {
      this.handleData()
    })
  }
}

export function onRefresh() {
  this.setState({ refreshing: true });
  const { data } = this.props
  const { dataList: { size } } = this.state
  this.setState({
    dataList: defaultDataList
  }, () => {
    this.handleData().finally(() => { this.setState({ refreshing: false }) })
  })
}

export function concatDataList(res) {
  this.setState({
    dataList: {
      ...res.data,
      records: this.state.dataList.records.concat(res.data.records)
    }
  })
}


export function onSelectiveRefresh(data) {
  /** 
   * 原始数据
   * [1 2 3 4 5 6 7 8 9 10] [11 12 13 14 15 16 17 18 19 20] [21 22 23 24 25 26 27 28 29 30]
   * 
   * 删除一条数据后
   * [1 2 3 4 6 7 8 9 10 11] [12 13 14 15 16 17 18 19 20 21] [22 23 24 25 26 27 28 29 30 '缺一条数据']
   * 
   * 解决方法，先获取删除的数据的当前页10条，做一下数据的合并
   * 
   * 给最后一页补一条数据
  */
  const { dataList } = this.state
  // 可以获取到被删除的数据所在页
  // let current = Math.ceil(orderEq / size)
  // let query = {
  // current,
  // size: dataList.size,
  // }

  // 转换新的数据，防止不刷新的情况
  let newDataList = { ...dataList }
  let orderEq = null
  // 截取掉被删除的数据
  newDataList.records.map((item, index) => {
    if (item.id == data.id) {
      orderEq = index
      newDataList.records.splice(index, 1)
    }
  })

  this.loading = Toast.loading('加载中', 0)
  this.handleData({
    current: dataList.current,
    size: dataList.size,
  }, 'selectiveRefresh').then(res => {
    let appendData = res.data.records.pop()
    if (newDataList.records[newDataList.records.length - 1].id == appendData.id) {
      // 最后一条数据跟新的数据是同一条
    } else {
      newDataList.records = newDataList.records.concat(appendData)
    }
    this.setState({
      dataList: {
        ...newDataList,
      }
    })
  }).catch(error => {
    console.log(error, 11111)
  }).finally(() => {
    Portal.remove(this.loading)
  })
}


export function requestCardLike(options) {
  this.loading = Toast.loading('加载中', 0)
  return cardLike(options).then(res => {
    Toast.success(res.message, 1.5)
  }).finally(() => {
    Portal.remove(this.loading)
  })
}

export function requestPlateFollow(options) {
  this.loading = Toast.loading('加载中', 0)
  return plateFollow(options).then(res => {
    Toast.success(res.message, 1.5)
  }).finally(() => {
    Portal.remove(this.loading)
  })
}

export function requestCardFollowAccount(options) {
  this.loading = Toast.loading('加载中', 0)
  return cardFollowAccount(options).then(res => {
    Toast.success(res.message, 1.5)
  }).finally(() => {
    Portal.remove(this.loading)
  })
}

export function handleAppraise(order) {
  console.log(order)
  let appraise = false
  order.orderGoodsList.map(item => {
    if (item.appraise == 0) {
      appraise = true
    }
  })
  return appraise
}
